//
//  MFAPMDBManager.m
//  MFAPMManager
//
//  Created by zhang liyu on 2019/5/29.
//

#import "MFAPMDBManager.h"

#import "MFAPMDataBase.h"
#import "MFAPMManager.h"
#import "MFAPMConfig.h"

@interface MFAPMDBManager()

@end

@implementation MFAPMDBManager

#pragma mark - Life Circle

- (void)dealloc{
    [MFAPMDataBase closeDB];
}

#pragma mark - Data Manager Actions

+ (void)storeDataItemsToDisk:(NSArray<NSDictionary *> *)dataItemsArr{
    if(![dataItemsArr isKindOfClass:[NSArray class]]
       || dataItemsArr.count == 0){
        return;
    }
    NSArray<NSDictionary *> *storeItemsArr = [[NSArray arrayWithArray:dataItemsArr] mutableCopy];
    NSUInteger diskTableLimitNUM = [[MFAPMManager sharedManager].config maxDiskCacheNUM];
    
    [MFAPMDataBase addItems:storeItemsArr withTableLimitItemNUM:diskTableLimitNUM complete:^(BOOL isSuccess) {
        //根据操作结果进行后续处理
    }];
}

+ (NSArray<NSDictionary *> *)fetchDiskAllDataItems{
    return [[self class] fetchDiskAllDataItemsAndClearTable:NO];
}

+ (NSArray<NSDictionary *> *)fetchDiskAllDataItemsAndClearTable:(BOOL)isClear{
    return [MFAPMDataBase queryAllItemsOrderInAsc:YES AndDeleteAllData:isClear];
}


@end
